package com.kaishengit.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Project;
import com.kaishengit.service.ProjectService;
import com.kaishengit.util.web.ServletUtil;

public class ProjectEdit extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		String id = request.getParameter("id");
		Project p = new ProjectService().findByProjectId(id);
		request.setAttribute("p", p);
		ServletUtil.forward(request, response, "project_edit");
	
	}
	
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		
		String id = request.getParameter("id");
		String name = request.getParameter("name");
		String desc = request.getParameter("desc");
		
		ProjectService service = new ProjectService();
		Project p = service.findByProjectId(id);
		p.setName(name);
		p.setDesc(desc);
		service.update(p);
		
		ServletUtil.redirect(response, "list.jspx");
	}

}
